package pers.wchen.mybatis.generate.tag;

import pers.wchen.mybatis.generate.model.DataComposeVO;
import pers.wchen.mybatis.generate.model.DatabaseTablePropertyVO;
import pers.wchen.mybatis.generate.model.FileInfoVO;
import pers.wchen.mybatis.generate.util.CharsTransUtil;
import pers.wchen.mybatis.generate.util.DateUtil;

import java.util.Set;

/**
 * @作者： wchen
 * @描述：  未写
 * @创建时间： 2018/2/13 23:42
 * @版本：Copyright 2018, Inc. All Rights Reserved.
 * @修改信息：
 */
public class TestTagManager extends AbsTagManager {

    public TestTagManager(DataComposeVO dataComposeVO, String tableName, String buildFileTag) {
        super(dataComposeVO, tableName, buildFileTag);
    }

    /**
     *  @描述:
     *  @参数： [templateStr]
     *  @返回值： java.lang.String
     *  @创建人: wchen
     *  @创建时间: 2018/2/13
     *  @修改人和其它信息:
     */
    public String replaceFileParam(String templateStr) {

        FileInfoVO fileInfoVO = this.fileInfoMap.get(this.buildFileTag);
        String replaceTemplateStr = templateStr.replace("&{param.package}", fileInfoVO.getPackageName())
                .replace("&{param.lowerClassName}", fileInfoVO.getLowerClassName())
                .replace("&{param.tableComponent}", this.tableComponent)
                .replace("&{param.dateTime}", DateUtil.getNowTime())
                .replace("&{param.className}", fileInfoVO.getClassName())
                ;
//        System.out.println("替换参数后的字符串");
//        System.out.println(replaceTemplateStr);
        return replaceTemplateStr;
    }

    /**
     * @param dealLine
     * @描述: 循环标签处理
     * @参数：
     * @返回值：
     * @创建人: wchen
     * @创建时间: 2018/2/13
     * @修改人和其它信息:
     */
    public String replaceLoopStock(String dealLine, Set<String> exIncludeFields) {
        StringBuffer loopSbf = new StringBuffer();
        for(DatabaseTablePropertyVO propertiesVO : this.databaseTablePropertyVOS){
            if(exIncludeFields.contains(propertiesVO.getField())){
                System.out.println("包含" + propertiesVO.getField());
                continue;
            }
            loopSbf.append(dealLine
                    .replace("&{param.comment}", propertiesVO.getComment())
                    .replace("&{param.javaType}", propertiesVO.getJavaType())
                    .replace("&{param.transField}", propertiesVO.getTransField())
                    .replace("&{param.upTransField}", CharsTransUtil.upperCaseFist(propertiesVO.getTransField()))
            ).append("\n");
        }
        return loopSbf.toString();
    }
}
